<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/token.jsp"%>
<%
	Integer uid = token.getUid();
	List<Map> templates =  QBuilder.db("basedb").select("new map(id as template_id, template_name as title, template_type as detail)").from("visit_template").where(new Where("status = ", STATUS_ENABLE).and("category=1").and("uid=", uid)).query().getResultObj();
	List<Integer> templatesUsed =  QBuilder.db("basedb").select("distinct score").from("Visit").where(new Where("status = ", STATUS_ENABLE).and("doctorUid=", uid)).query().getResultObj();
	if (isEmpty(templates)) {
        msg = new Message(30041, "暂无随访模板");
    }
	for (Map template:templates) {
		Integer templateId = (Integer)template.get("template_id");
		template.put("is_used", 0);
		if (templatesUsed.contains(templateId))
			template.put("is_used", 1);
	}
    msg.put("data", templates);
    Tools.encryptPrint(out, msg);
%>